package com.example.patients.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.patients.R;
import com.example.patients.entity.PatientsBean;

import java.util.List;


public class Adapter_update extends BaseAdapter {
    Context context;
    List<PatientsBean> mData;
    LayoutInflater inflater;
    public Adapter_update(Context context, List<PatientsBean> mData) {
        this.context = context;
        this.mData = mData;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_patient_update, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        PatientsBean bean=mData.get(position);
        holder.TvNumber.setText("病床号:"+bean.getNumber());
        holder.TvName.setText("姓名:"+bean.getName());
        holder.TvYear.setText("年龄:"+bean.getYear());
        holder.TvSex.setText("性别:"+bean.getSex());
        holder.TvBirth.setText("病因:"+bean.getSickness());
        holder.TvAddress.setText("禁忌史:"+bean.getTaboo());
        holder.TvPhone.setText("电话:"+bean.getPhone());
        return convertView;
    }
    class ViewHolder {
        TextView TvNumber,TvName, TvYear, TvSex, TvBirth,TvAddress,TvPhone;

        public ViewHolder(View view) {
            TvNumber= view.findViewById(R.id.tv_number);
            TvName = view.findViewById(R.id.tv_name);
            TvYear = view.findViewById(R.id.tv_year);
            TvSex = view.findViewById(R.id.tv_sex);
            TvBirth = view.findViewById(R.id.tv_sickness);
            TvAddress = view.findViewById(R.id.tv_taboo);
            TvPhone = view.findViewById(R.id.tv_phone);

        }
    }
}
